
/*
@ auth	hdg
@ email	  hdg1988@gmail.com
@ date	2010-3-26
快速启动按钮定义 reg 组装按钮
*/

var quickMenu_FUN=function(){
		//继承
		baseMenu.call(this);
		var moreQuickMenuTemplate='<div class="moreQuickMenu" ><img src="image/more_quickMenu.jpg"></div>';
		var otherQuickMenusTemplate='<div class="otherQuickMenu"></div>';
		var menuHtmlWithOutDesc=[];
		var menuHtmlWithDesc=[];
		var hide_def=function(){
			$(".otherQuickMenu").addClass("div_hide");
		}
		var moreQuickMenuClick=function(event){
			var otherQuickMenu=$(".otherQuickMenu");
			if(hasClassName("div_hide",".otherQuickMenu")){
				otherQuickMenu.removeClass("div_hide");
			}else{
				otherQuickMenu.addClass("div_hide");
			}
			(new startMenu_FUN()).hide();
		}
		this.init=function(){
			//组装按钮
			for(var i=0;i<this.menus.length;i++){
				if(this.menus[i].show)
					menuHtmlWithOutDesc.push($format(this.menuTemplate,	[this.menus[i].key,this.menus[i].title,this.menus[i].imgSrc,this.menus[i].show,this.menus[i].desc]));
				else
					menuHtmlWithDesc.push($format(this.menuTemplate,	[this.menus[i].key,this.menus[i].title,this.menus[i].imgSrc,this.menus[i].show,this.menus[i].desc]));
				//组装适配器
				EventAdapter.reg(this.menus[i].key.toUpperCase(),this.menus[i].cmd);
			}
			if(!document.getElementById(this.renderTo))
				return;
			$("#"+this.renderTo).html(menuHtmlWithOutDesc.join(""));
			//如果有隐藏的快速启动按钮
			if(menuHtmlWithDesc.length>0){
				$("#"+this.renderTo).html(menuHtmlWithOutDesc.join("")+moreQuickMenuTemplate);
				//TODO：0.在其它快捷按钮模板上添加按钮
				
				$(otherQuickMenusTemplate).html(menuHtmlWithDesc.join("")).appendTo("#"+this.renderTo).css({
					position:'absolute',
					background:'white',
					width:200
				}).addClass("div_hide");
				this.setStyle();
				//TODO：1.this.renderTo上添加其它快捷按钮模板,position:absolute，设置top和left hidden
				this.eventBind();
			}
		}
		this.setStyle=function(){
			var offset = $(".moreQuickMenu").eq(0).offset();
			$(".otherQuickMenu").css({
				top:offset.top-21*menuHtmlWithDesc.length,//每个高度是20px？
				left:offset.left
			});
		}
		this.eventBind=function(){
				
				// =======================TODO 这可能需要底层设计===========================
				//设置moreQuickMenu onclick事件
				$(".moreQuickMenu").bind("click",moreQuickMenuClick);
				//=======================================================================
				//鼠标悬停事件
				$(".otherQuickMenu .quickMenu").bind("mouseover",this.mouseover);
				$(".otherQuickMenu .quickMenu").bind("mouseout",this.mouseout);
				// 点击事件
				$(".quickMenu").bind("click",this.click);
				// 更多快捷按钮禁止冒泡
				stopElemEvent("click",".moreQuickMenu");
		}
		this.mouseover=function(event){
			if(checkHover(event,this)){
				$(this).addClass("mouseover");
			}
		}
		this.mouseout=function(event){
			if(checkHover(event,this)){
				$(this).removeClass("mouseover");
			}
		}

		this.click=function(event){
			hide_def();
			EventAdapter.exec($(this).attr("key").toUpperCase());
		}
		
		//hotKeyTemplate:'<span class="hotkey">{0}</span>',
		//separateTemplate:'<div class="quickmenu item"><div class="separate"></div></div>',
		this.menuTemplate=[
			'<div class="quickMenu" title="{1}" key="{0}">',
				'<img src="{2}"/>',
				'<div class="menuDesc_{3}">',
					'<span>{4}</span>',
				'</div>',
				//'<div class="menuContent" style="display:none;">{5}</div>',
			'</div>'
		].join("")

		this.hide = hide_def;
	}
//继承
//quickMenu_FUN.prototype = new baseMenu();


	// 运行程序按钮
	/*
@ auth	hdg
@ email	  hdg1988@gmail.com
@ date	2010-3-26

*/
var processMenu_FUN=function(){
		baseMenu.call(this);
		this.menuTemplate=[
			'<div class="processMenu processMenu_{3}" title="{1}" key="{0}">',
				'<img src="{2}"/>',
			'</div>'
		].join("")
		var seperateTemplate='<div class="process_seperate" ><img src="image/norman_seperate.jpg"/></div>'
		this.init=function(){
			//组装按钮
			var html=seperateTemplate;
			for(var i=0;i<this.menus.length;i++){
				html +=$format(this.menuTemplate,	[this.menus[i].key,this.menus[i].title,this.menus[i].imgSrc,this.menus[i].show]);
				//组装适配器
				EventAdapter.reg(this.menus[i].key.toUpperCase(),this.menus[i].cmd);
			}
			if(!document.getElementById(this.renderTo))
				return;
			$(html).appendTo("#"+this.renderTo);
			$(".processMenu_false").width(0);
			// =======================TODO 这可能需要底层设计===========================
			this.eventBind();
		}
		this.eventBind=function(){
			//设置moreQuickMenu onclick事件
			$(".process_seperate").toggle(function(){
					$(".processMenu_false").animate({
						width:'+20px'},300);
					setTimeout(function(){$(".process_seperate img").attr("src","image/norman_seperate_back.jpg")},300);
				},function(){
					$(".processMenu_false").animate({
						width:'0'},300);
					setTimeout(function(){$(".process_seperate img").attr("src","image/norman_seperate.jpg")},300);
			});
			// 点击事件
			$(".processMenu").bind("click",this.click);
			//=======================================================================
		}
		this.click=function(event){
			EventAdapter.exec($(this).attr("key").toUpperCase());
		}
	}


	//开始菜单的子节点
	var childrenItems=function(){
		var parentKey_def='';
		var items_def=[];
		var childrenItems={};
		var itemsTemplate_def="<div class='startMenu_items {0}_children' parentkey='{0}'>{1}</div>";
		var itemTemplate_def=["<div class='startMenu_item mouseout' hasChildren={4} title='{0}' key='{1}'>",
				"<img src='{2}' class='{5}'/>",
				"<div class='item_desc'>{3}</div>",
				"<div class='{1}_parent children'></div>",
				"<div class='children_{4}'></div>",
		"</div>"].join("");
		var seperateTemplate_def="<div class='seperate_item'><div class='seperate'></div></div>";
		var init_def=function(_parentKey,_items){
			parentKey_def=_parentKey;
			items_def=_items;
			//this.divId=this.parentKey+"_children";
			initHTML_def();
			eventBind_def();
		}
		var initHTML_def=function(){
			var html ="";
			for(var i=0;i<items_def.length;i++){
				var item = items_def[i];
				var hasItems = item.items && item.items.length>0?true:false;
				var hasImg = item.imgSrc && item.imgSrc.length>0?true:false;
				if(item.key=='seperate'){
					html+=seperateTemplate_def;
				}else{
					html+=$format(itemTemplate_def,[item.title,item.key,item.imgSrc,item.desc,hasItems,hasImg?"":"null"]);
				}
				if(hasItems){
					childrenItems[item.key]=item.items;
				}
				//组装事件适配器
				EventAdapter.reg(item.key.toUpperCase(),item.cmd);
			}
			html=$format(itemsTemplate_def,[parentKey_def,html]);
			$(html).appendTo("."+parentKey_def+'_parent');
			//设置position
			setStyle_def(parentKey_def);
		}
		var eventBind_def=function(){
			//mouseon事件
			$(".startMenu_item").bind("mouseover",mouseover_def);
			$(".startMenu_item").bind("mouseout",mouseout_def);
			//click事件 点击事件
			$(".startMenu_item").bind("click",click_def);
		}
		//???????????????????????????????????????????
		
		var initItems=function(_key){

			var items=childrenItems[_key];
			//for(var i=0; i<this.menus.length; i++){
			//	if(this.menus[i].key==_key && this.menus[i].items && this.menus[i].items.length>0){
			//		items=this.menus[i].items;
			//	}
		//	}
					
			if(!items)
				return;
			init_def(_key,items);
		}
		//某个按钮的mouseout事件
		var menuMouseOut = function(el){
			var key = $(el).attr("key");
			var childrenBoardElem = $("."+key+"_children").get(0);
			//本身的mouseout事件
			if(hasClassName('mouseover',el))
				$(el).removeClass("mouseover").addClass("mouseout");
			//如果没有子按钮
			if(!childrenBoardElem)
				return;
			var children = childrenBoardElem.childNodes;
			for(i=0;i<children.length;i++){
				if(hasClassName("mouseover",children[i])){
					menuMouseOut(children[i]);
					//$(children[i]).removeClass("mouseover").addClass("mouseout");
				}
			}
			//隐藏这个按钮组
			if(!hasClassName('div_hide',childrenBoardElem))
				$(childrenBoardElem).addClass('div_hide');
		}
		var doWithOtherNodes=function(el){
			var children =el.parentNode.childNodes;
			for(var i=0;i<children.length;i++){
				var child = children[i];
				if(child==el)
					continue ;
				//如果已经是mouseover，则说明上次展开的是这个节点，需要将其子节点都关闭。
				if(hasClassName("mouseover",child)){
					menuMouseOut(child);
					$(child).removeClass("mouseover");
					$(child).addClass("mouseout");
				}
			}
		}
		
		var mouseover_def=function(event){
			if(checkHover(event,this)){

				//遍历其兄弟节点，将他们设置成mouseout状态
				doWithOtherNodes(this);

				if(hasClassName("mouseout",this)){
					$(this).removeClass("mouseout");
					$(this).addClass("mouseover");
				}
				// get key
				var key=$(this).attr("key");
				//动态构造子元素
				if(!$("."+key+"_children").get(0))
					initItems(key);
				if(key && $("."+key+"_children").get(0)){
					$("."+key+"_children").removeClass("div_hide");
					setStyle_def("."+key+"_children",key);
				}
			}
			return false;
		}
		var click_def=function(event){
			if($(this).attr("hasChildren")=="false"){
				$(".startMenuBoard").click().addClass("div_hide");
				EventAdapter.exec($(this).attr("key").toUpperCase());
			}
			return false;
		}
		
		var mouseout_def=function(event){
			if(checkHover(event,this)){
				var key = $(this).attr('key');
				//如果没有孩子节点，则将其设置为mouseout状态
				if(!$("."+key+"_children").get(0))
					$(this).removeClass("mouseover").addClass("mouseout");
				/*$(this).removeClass("mouseover").addClass("mouseout");
				var key=$(this).attr("key");
				var childEle=$("."+key+"_children");
				if(key && childEle.get(0))
					childEle.addClass("div_hide");
				*/
			}
		}
		var setStyle_def=function(_parentKey){
			//alert(_parentKey)
			var childrenBoard = $("."+_parentKey+"_children");
			var parentBoard = $("."+_parentKey+'_parent');
			var startMenuBoart = $(".startMenuBoard");
			if(parentBoard.offset().top+childrenBoard.height()-$(window).height()>0){
				childrenBoard.css({
					position:'absolute',
					top:parentBoard.offset().top-startMenuBoart.offset().top+parentBoard.parent().height()-childrenBoard.height()+2
				});
			}
			//alert();
		}
		this.init =init_def;
		this.initHTML=initHTML_def;
		this.initItems = initItems;
		this.items = items_def;
		this.setStyle = setStyle_def;
		this.mouseover=mouseover_def;
		this.mouseout =mouseout_def;
		this.click =click_def;
		this.eventBind =eventBind_def;
		this.parentKey=parentKey_def;
		this.seperateTemplate=seperateTemplate_def;
		this.itemsTemplate=itemsTemplate_def;
		this.itemTemplate=itemTemplate_def;
	}
/*
	@ auth	hdg
	@ email	  hdg1988@gmail.com
	@ date	
	start_menu开始菜单
	reg([{
		key:,
		desc:,
		title:,
		position:,
		imgSrc:,
		items:[{},{}],
		cmd:
	*/
var startMenu_FUN=function(){
		baseMenu.call(this);
		var headHTML="";
		var bodyHTML="";
		var body_bottomHTML="";
		var bottomHTML="";
		var menus=null;
		var childItem = new childrenItems();
		var headTemplate=["<div class='head'>",
					"<img src='{0}'/>",
					"<div>{1}</div>",
				"</div>"].join("");
		var bodyTemplate=["<div class='body'>",
					"<div class='left' id='left_startMenu'></div>",
					"<div class='right' id='right_startMenu'></div>",
				"</div>"].join("");
		var body_bottomTemplate=["<div class='body_bottom'>",
					"<div class='body_bottom_left'>",
						"<div class='seperate'></div>",
						"<div class='startMenu allprogram' key='allprogram'>",
							"<div class='allprogram_menuDesc'>所有程序</div>",
							"<div class='allprogram_img'></div>",
							"<div class='allprogram_parent'></div>",
						"</div>",
					"</div>",
					"<div class='body_bottom_right'></div>",
			"</div>"].join("");
		var bottomTemplate=["<div class='bottom'>",
					"<div>{1}</div>",
					"<img src='{0}'/>",
				"</div>"].join("");
		var menuBoardTemplate =["<div class= 'startMenuBoard'>",
			"</div>"].join("");
		this.menuTemplate= ['<div class="startMenu {0} mouseout" hasChildren="{4}" title="{1}" key="{0}">',
				'<img src="{2}"/>',
				'<div class="menuDesc">',
					'<span>{3}</span>',
				'</div>',
				'<div class="{0}_parent children"></div>',
				'<div class="children_{4}"></div>',
			'</div>'].join("");
		var menuBoardClick=function(event){
			var menuBoard = $(".startMenuBoard");
			if(!hasClassName("div_hide",".startMenuBoard")){
					menuBoard.addClass("div_hide");
			}else{
				menuBoard.removeClass("div_hide");
			}
			//------------------------------------------------------------------------------------
			(new quickMenu_FUN).hide();
		}
		var initHead=function(_imgSrc , _userName){
			headHTML=$format(headTemplate,[_imgSrc,_userName]);
		}
		var initBody=function(){
			bodyHTML=bodyTemplate;
		}
		var initBody_bottom=function(){
			body_bottomHTML=body_bottomTemplate;
		}
		var initBottom=function(_imgSrc , _info){
			bottomHTML=$format(bottomTemplate,[_imgSrc,_info]);
		}
		
		//动态构造子元素
		var initItems_def=function(_key){
			var items;
			for(var i=0; i<menus.length; i++){
				if(menus[i].key==_key && menus[i].items && menus[i].items.length>0){
					items=menus[i].items;
				}
			}
			if(items)
				childItem.init(_key,items);
		}
		var setHeight=function(){
			var height1=$("#right_startMenu").height();
			var height2=$("#left_startMenu").height();

			var maxHeight = height1>height2?height1:height2;
			$("#right_startMenu").height(maxHeight);
			$("#left_startMenu").height(maxHeight);
		}
		this.init=function(){
			menus = this.menus;
			this.initHTML();
			//设置两边一样高
			setHeight();
			this.eventBind();
			this.setStyle();
			this.hide();
		}
		this.initHTML=function(){
			var rightMenu="";
			var leftMenu="";
			for(var i=0;i<this.menus.length;i++){
				var hasChildren=(this.menus[i].items && this.menus[i].items.length>0)?"true":"false";
				if(this.menus[i].position=='left'){
					if(this.menus[i].key=='seperate')
						leftMenu+=this.seperateTemplate;
					else
						leftMenu+=$format(this.menuTemplate,[this.menus[i].key,this.menus[i].title,this.menus[i].imgSrc,this.menus[i].desc,
					hasChildren]);
				}else if(this.menus[i].position=='right'){
					if(this.menus[i].key=='seperate')
						rightMenu+=this.seperateTemplate;
					else
						rightMenu+=$format(this.menuTemplate,[this.menus[i].key,this.menus[i].title,this.menus[i].imgSrc,this.menus[i].desc,
					hasChildren]);
				}
				//组装事件适配器
				EventAdapter.reg(this.menus[i].key.toUpperCase(),this.menus[i].cmd);
			}
			$(menuBoardTemplate).appendTo("#"+this.renderTo);
			//初始化头 中 尾
			initHead('image/buttlefly.jpg','Administrator');
			initBody();
			initBody_bottom();
			initBottom('image/Exit.png','Exit');
			//添加到页面中
			$(".startMenuBoard").append(headHTML+bodyHTML+body_bottomHTML+bottomHTML);

			if(rightMenu.length>0){
				//document.write(rightMenu);
				//$("#right_startMenu").append(this.seperateTemplate);
				$(rightMenu).appendTo("#right_startMenu");
			}
			if(leftMenu.length>0)
				$(leftMenu).appendTo("#left_startMenu");

		}

		this.setStyle=function(){
			var top=$(".bottom_bar").offset().top-$(".startMenuBoard").eq(0).height();
			$(".startMenuBoard").css({
				top:top,
				left:'0px'
			})
		}

		this.eventBind=function(){
			//显示事件
			$("#"+this.renderTo).bind("click",menuBoardClick);
			//mouseon事件
			$(".startMenu").bind("mouseover",this.mouseover);
			$(".startMenu").bind("mouseout",this.mouseout);
			//click事件 点击事件
			$(".startMenu").bind("click",this.click);
			$(".startMenuBoard").bind("click",this.startMenuBoardClick);
			//禁止冒泡
			stopElemEvent("click",".startMenuBoard");
			stopElemEvent("click","#"+this.renderTo);
		}
		this.startMenuBoardClick=function(){
			doWithOtherNodes();
		}
		//某个按钮的mouseout事件
		var menuMouseOut = function(el){
			var key = $(el).attr("key");
			var childrenBoardElem = $("."+key+"_children").get(0);
			//本身的mouseout事件
			if(hasClassName('mouseover',el))
				$(el).removeClass("mouseover").addClass("mouseout");
			//如果没有子按钮
			if(!childrenBoardElem)
				return;
			var children = childrenBoardElem.childNodes;
			for(i=0;i<children.length;i++){
				if(hasClassName("mouseover",children[i])){
					menuMouseOut(children[i]);
					//$(children[i]).removeClass("mouseover").addClass("mouseout");
				}
			}
			//隐藏这个按钮组
			if(!hasClassName('div_hide',childrenBoardElem))
				$(childrenBoardElem).addClass('div_hide');
		}
		var doWithOtherNodes=function(el){
			var nodes = $(".startMenu");
			for(var i = 0 ;i<nodes.size();i++){
				if(el==nodes.get(i)){
					continue;
				}
				if(hasClassName("mouseover",nodes.get(i))){
					menuMouseOut(nodes.get(i));
				}
			}
		}
		this.mouseover=function(event){
			if(checkHover(event,this)){
				//先对其他的按钮进行处理
				doWithOtherNodes(this);

				$(this).addClass("mouseover").removeClass("mouseout");
				// get key
				var key=$(this).attr("key");
				//动态构造子元素
				if(!$("."+key+"_children").get(0)){
					initItems_def(key);
					// 设置位置
				}
				if(key && $("."+key+"_children").get(0)){
					$("."+key+"_children").removeClass("div_hide");
				}
			}
		}

		this.mouseout=function(event){
			if(checkHover(event,this)){
				//如果没有子按钮，则置为mouseout状态
				var key = $(this).attr('key');
				var childrenBoard = $("."+key+"_children").get(0);
				//如果有子按钮
				if(childrenBoard)
					return;
				$(this).removeClass("mouseover").addClass("mouseout");
				//if(key)
				/*$(this).removeClass("mouseover").addClass("mouseout");
				var key=$(this).attr("key");
				var childEle=$("."+key+"_children");
				if(key && childEle.get(0)){
					childEle.addClass("div_hide");
					//hideMenuBoard("."+key+"_children");
				}
				*/
			}
		}
		this.click=function(event){
			if($(this).attr("hasChildren")=="false"){
					$(".startMenuBoard").addClass("div_hide");
					EventAdapter.exec($(this).attr("key").toUpperCase());
			}
		}
		
		this.hide=function(){
			if(!hasClassName("div_hide",".startMenuBoard"))
				$(".startMenuBoard").click().addClass("div_hide");
		}
		this.initItems=initItems_def;
}

function getParent(obj){
	return $(obj).parent().get(0);
}

/*
	@ auth	huangpf
	@ email	hpf1908@gmail.com
	@ date	
	*/
function noteBookMenu(id){
	
	baseMenu.call(this);
	
	this.id=id;
	
	this.menuBarTemplate = "<div id='{0}_menuBar' class='menuBar' isClick=false mouseOverItem=''></div>";
	
	this.menuItem = "<div class='menuItem' id='menuItem_{0}' >"+
	                   "<div class='desc'>{1}</div>"+
	                "</div>";
												
	this.menuSubItems ="<div class='menuSubItems' mouseOverItem='' id='menuSubItems_{0}'></div>";
	
	this.menuSubItem = "<div class='menuSubItem' id='menuSubItem_{0}'>"+
												"<div class='desc'>{1}</div>"+
											"</div>";
											
	this.seperateTemplate='<hr></hr>';
	
	this.init=function(){
		this.initHTML();
		this.eventBind();
		this.setStyle();
	}	
	
	this.initHTML=function(){
		var html='';
					
		this.menuBarTemplate=$format(this.menuBarTemplate,[this.id]);
		$("#"+this.renderTo).append(this.menuBarTemplate);	
		
		for(var i=0;i<this.menus.length;i++){
			
			html= $format(this.menuItem,[i,this.menus[i].desc]);
			$(html).appendTo("#"+this.id+"_menuBar");
			
			var hasChildren=(this.menus[i].items && this.menus[i].items.length>0)?true:false;
			
			if(hasChildren==true){
				var children=this.menus[i].items;	
				this.menuSubItems=$format(this.menuSubItems,[this.id]);
				
				$(this.menuSubItems).appendTo("#"+this.id+"_menuBar #menuItem_"+i);		

				html="";		
				for(var j=0;j<children.length;j++){
					if(children[j].key!='seperate'){
						html+=$format(this.menuSubItem,[j,children[j].desc]);
						EventAdapter.reg(children[j].key.toUpperCase(),children[j].cmd);
					}
					else
						html+=this.seperateTemplate;
				}
				$(html).appendTo("#"+this.id+"_menuBar #menuItem_"+i+" .menuSubItems");
			}	

		}
	}
	
	this.setStyle=function(){
		$("#"+this.id+"_menuBar .menuSubItems").hide();

		$("#"+this.id+"_menuBar .menuSubItems").css({
				position:'absolute',
				background:'white',
				width:130+'px'
		});
	}
	
	this.eventBind=function(){
			//禁止冒泡
			stopElemEvent("mousedown",".menuBar .menuItem");		
			stopElemEvent("mouseover",".menuBar .menuItem");	
			stopElemEvent("mouseover",".menuBar .menuSubItems");	
			stopElemEvent("mouseout",".menuBar .menuSubItems");	
			stopElemEvent("mouseout",".menuBar .menuSubItem");	
			//显示事件
			$(".menuBar .menuItem").bind("mouseover",this.menuItemMouseOver);
			$(".menuBar .menuItem").bind("mousedown",this.menuItemDown);
			$(".menuBar .menuItem").bind("mouseout",this.menuItemMouseOut);
			$(".menuBar .menuSubItems").bind("mouseout",this.menuSubItemsMouseOut);
			$(".menuBar .menuSubItems").bind("mouseover",this.menuSubItemsMouseOver);
			$(".menuBar .menuSubItem").bind("mouseover",this.menuSubItemMouseOver);
	}
	
	this.menuItemMouseOver=function(){
		var parent=getParent(this);
		var id=parent.id;
		
		//切换item背景色
		var mouseOverItemId=parent.mouseOverItem;
		if(mouseOverItemId!=''){
			$("#"+id+" #"+mouseOverItemId).css({
				background:'#ece9d8',
				color:'black'
			});		
		}
		$(this).css({
				background:'#0066cc',
				color:'white'	
		});
		parent.mouseOverItem=$(this).attr('id');
						
						
		var subitems=$("#"+id+" #"+this.id+" .menuSubItems").get(0);
		if(subitems!=null){
			var mouseOverSubItemId=subitems.mouseOverItemId;
			if(mouseOverSubItemId!=''){
					$("#"+id+" #"+mouseOverSubItemId).css({
						background:'white',
						color:'black'
					});		
				subitems.mouseOverItemId='';
			}
		}
		
		if(parent.isClick==true){		
			$("#"+id+" #"+this.id+" .menuSubItems").show();
			$("#"+id+" #"+this.id+" .menuSubItems").css({
					color:'black'
			});
			if(mouseOverItemId!=$(this).attr('id'))
				$("#"+id+" #"+mouseOverItemId+" .menuSubItems").hide();
		}
	}
	
	this.menuSubItemMouseOver=function(){
		var parent=getParent(this);
		var id=parent.id;
		
		//切换item背景色
		var mouseOverItemId=parent.mouseOverItem;
		if(mouseOverItemId!=''&&mouseOverItemId!=$(this).attr('id')){
			$("#"+id+" #"+mouseOverItemId).css({
				background:'white',
				color:'black'
			});		
		}
		$(this).css({
				background:'#0066cc',
				color:'white'	
		});
		parent.mouseOverItem=$(this).attr('id');				
	}
	
	this.menuItemMouseOut=function(){
		$(this).css({
				background:'#ece9d8',
				color:'black'	
		});
	}
	
	this.menuItemDown=function(){	
		getParent(this).isClick=true;
		$("#"+getParent(this).id+" #"+this.id+" .menuSubItems").css({
					color:'black'
			});
		$("#"+getParent(this).id+" #"+this.id+" .menuSubItems").show();
	}
	
	this.menuSubItemsMouseOver=function(){
		$(this).show();
	}
	
	this.menuSubItemsMouseOut=function(){	
		if(checkHover(event,this)){
			var mouseOverItemId=$(this).attr('mouseOverItem');
			if(mouseOverItemId!=''){
				$("#"+this.id+" #"+mouseOverItemId).css({
					background:'white',
					color:'black'
				});		
			}
			$(this).hide();
		}
	}
}

/*
	@ auth	huangpf
	@ email	hpf1908@gmail.com
	@ date	
	*/
function windowTaskMenu(){
	
	baseMenu.call(this);	
	
	this.activeWin='';
		
	this.taskItem="<div class='window_task' id='{0}' parent='{1}'>"+
			            "<div class='icon'><img src='{2}'></img></div>"+
			            "<div class='desc'>{3}</div>"+
		            "</div>";
		            
	this.init=function(){
		this.initHTML();
		this.eventBind();
	}	
		
	this.initHTML=function(){		
		for(var i=0;i<this.menus.length;i++){	
			html= $format(this.taskItem,[this.renderTo+'_'+this.menus[i].id,this.renderTo,this.menus[i].imgSrc,this.menus[i].desc]);
			$(html).appendTo("#"+this.renderTo);
		}
		
		//添加到组件管理者							
		compManager.push(this.renderTo,this);
	}
	
	//panel会自动隐藏
	this.minWindow=function(){
		windowTaskManager.removeActiveWin();
	}
	//清除panel节点和Menu节点
	this.closeWindow=function(){
		windowTaskManager.deleteWindow(this.id);	
	}
		
	//使当前窗口处于焦点
	this.focusWindow=function(){
		var temp=this.id.split('_');
		var menuid=windowTaskManager.renderTo+'_'+temp[0];
		windowTaskManager.setItemMouseDown(menuid);
		if(windowTaskManager.getActiveWin()!=''&&windowTaskManager.getActiveWin()!=menuid){
			windowTaskManager.setItemMouseOut(windowTaskManager.getActiveWin());
		}	
		windowTaskManager.setActiveWin(menuid);
		windowTaskManager.isOnWindow=true;
	}
	
	this.showWindow=function(id){
		var temp=id.split('_');	
		var panel=temp[1]+'_panel';
		if(this.getActiveWin()!=''){
				this.setItemMouseOut(this.getActiveWin());
		}	
		if($('#'+panel).css('display')=='none'){
			this.setItemMouseDown(this.renderTo+'_'+temp[1]);	
			this.setActiveWin(this.renderTo+'_'+temp[1]);
			$('#'+panel).show();
			$('#'+panel).css({
				zIndex:++dragresize.zIndex
			});
		}
		else{
			$('#'+panel).hide();	
			this.setActiveWin('');
		}
	}
	
	this.addMenu =function(_jsons){
		for(var i=0;i< _jsons.length;i++){
			html= $format(this.taskItem,[this.renderTo+'_'+_jsons[i].id,this.renderTo,_jsons[i].imgSrc,_jsons[i].desc]);
			$(html).appendTo("#"+this.renderTo);
			
			panel = new NoteBookPanel({
				id:_jsons[i].id,                    
				titleText:_jsons[i].desc,    
				titleImg:_jsons[i].imgSrc,
				left:50,
				top:150,
				width: 500,
				height: 400,
  		  OnMin:this.minWindow,
  		  OnClose:this.closeWindow,
  		  OnMouseDown:this.focusWindow
			});
			panel.init();
		}
		this.eventBind();
	}
	
	this.eventBind=function(){		
		$(".bottom_bar_window .window_task").bind("mouseover",this.windowTaskMouseOver);
		$(".bottom_bar_window .window_task").bind("mouseout",this.windowTaskMouseOut);
		$(".bottom_bar_window .window_task").bind("mousedown",this.windowTaskMouseDown);
		
		stopElemEvent("mousedown",".bottom_bar_window .window_task");	
	}
	
	this.windowTaskMouseOut=function(){	
		if(checkHover(event,this)){		
			var manager=compManager.getCmpById(this.parent);	
			if(manager!=null){
				if(manager.getActiveWin()!=this.id)
					manager.setItemMouseOut(this.id);
				else
					manager.setItemMouseDown(this.id);
			}
		}
	}
	
	this.windowTaskMouseOver=function(){	
		if(checkHover(event,this)){
			var manager=compManager.getCmpById(this.parent);	
			manager.setItemMouseOver(this.id);
		}
	}	
	
	this.setActiveWin=function(id){
		this.activeWin=id;
	}
	
	this.getActiveWin=function(){
		return this.activeWin;
	}
	
	this.setItemMouseOver=function(item){
		$("#"+item).css({
					background:'red'
				});
	}
	
	this.setItemMouseOut=function(item){
			$("#"+item).css({
					background:'blue'
				});
	}
	
	this.setItemMouseDown=function(item){
		$("#"+item).css({
					background:'black'
				});
	}
	
	this.windowTaskMouseDown=function(){
			var manager=compManager.getCmpById(this.parent);
			manager.showWindow(this.id);
	}
	
	this.removeActiveWin=function(){
		
		if(this.isOnWindow){
			this.isOnWindow=false;
			return;
		}
		if(this.getActiveWin()!=''){
			this.setItemMouseOut(this.getActiveWin());	
			this.setActiveWin('');		
		}	
	}
	
	this.deleteWindow=function(id){
		var windowid=id+'_panel';
		var taskid=this.renderTo+'_'+id;
		if(this.getActiveWin()==taskid){
			this.setActiveWin('');
		}
		$('#'+windowid).remove();	
		$('#'+taskid).remove();	
	}
}
